<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.blurry" clearable size="small" placeholder="姓名、身份证" style="width: 170px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.bisZhsqCblx" clearable size="small" placeholder="参保类型" class="filter-item" style="width: 120px" @change="crud.toQuery">
          <el-option
            v-for="item in cblxTypeOptions"
            :key="item.key"
            :label="item.display_name"
            :value="item.key"
          />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="660px">
        <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="110px">
          <el-form-item label="姓名" prop="bisZhsqSnryXm">
            <el-input v-model="form.bisZhsqSnryXm" disabled style="width: 170px;">
              <el-button slot="append" icon="el-icon-search" title="查找患者信息" @click="getSnry" />
            </el-input>
          </el-form-item>
          <el-form-item label="身份证" prop="bisZhsqSnrySfz">
            <el-input v-model="form.bisZhsqSnrySfz" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="性别" prop="bisZhsqSnryXb">
            <el-input v-model="form.bisZhsqSnryXb" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="年龄" prop="bisZhsqNl">
            <el-input v-model="form.bisZhsqNl" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="医保卡号" prop="bisZhsqYbkh">
            <el-input v-model="form.bisZhsqYbkh" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="参保状态" prop="bisZhsqCbzt">
            <el-input v-model="form.bisZhsqCbzt" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="参保类型" prop="bisZhsqCblx">
            <el-input v-model="form.bisZhsqCblx" disabled style="width: 170px;" />
          </el-form-item>
          <el-form-item label="医保所属区县" prop="bisZhsqSnryYbssqx">
            <el-select v-model="form.bisZhsqSnryYbssqx" filterable placeholder="请选择" disabled style="width: 170px;">
              <el-option
                v-for="item in dict.ccstcqh"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="行政区划" prop="districts">
            <el-cascader :options="districts" clearable style="width: 170px;" @change="onchange" />
          </el-form-item>
          <el-form-item label="地址" prop="bisZhsqHldz">
            <el-input v-model="form.bisZhsqHldz" style="width: 170px;" />
          </el-form-item>
          <el-form-item label="联系电话" prop="bisZhsqLxdh">
            <el-input v-model="form.bisZhsqLxdh" style="width: 170px;" />
          </el-form-item>
          <el-form-item label="监护人姓名" prop="bisZhsqJhrxm">
            <el-input v-model="form.bisZhsqJhrxm" style="width: 170px;" />
          </el-form-item>
          <el-form-item label="监护人电话" prop="bisZhsqJhrdh">
            <el-input v-model="form.bisZhsqJhrdh" style="width: 170px;" />
          </el-form-item>
          <el-form-item label="关系" prop="bisZhsqGx">
            <el-select v-model="form.bisZhsqGx" filterable placeholder="请选择" style="width: 170px;">
              <el-option
                v-for="item in dict.yjsgx"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="ADL量表评分" prop="bisZhsqAdl">
            <el-input v-model="form.bisZhsqAdl" readonly style="width: 170px;">
              <el-button slot="append" icon="el-icon-document" title="测量ADL量表" @click="getAdl" />
            </el-input>
          </el-form-item>
          <el-form-item label="申请类别" prop="bisZhsqSqlb">
            <el-select v-model="form.bisZhsqSqlb" filterable placeholder="请选择" style="width: 170px;">
              <el-option
                v-for="item in dict.sqlb"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="申请原因" prop="bisZhsqSqyy">
            <el-input v-model="form.bisZhsqSqyy" :rows="3" type="textarea" style="width: 470px;" />
          </el-form-item>
          <el-upload
            ref="upload_adl"
            :show-file-list="true"
            :auto-upload="true"
            :on-preview="handlePreview"
            :before-upload="beforeVideoUpload"
            :before-remove="beforeRemove"
            :on-remove="handleRemove"
            :on-success="handleVideoSuccess"
            :on-progress="handleProgress"
            :on-error="handleError"
            :data="fjlb_adl"
            :headers="headers"
            :file-list="file_list_adl"
            :action="formatVideo"
          >
            <el-button size="small" type="primary">上传视频</el-button>
            <span slot="tip" class="el-upload__tip">只能上传视频文件，且不超过150M</span>
          </el-upload>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button :loading="crud.status.cu === 2 || fileUploading" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2 || fileUploading" type="primary" @click="doSave('00')">保存</el-button>
          <el-button v-if="!sbIsExist" :loading="crud.status.cu === 2 || fileUploading" type="success" @click="doSubmit('54')">提交</el-button>
          <el-button v-else :loading="crud.status.cu === 2 || fileUploading" type="success" @click="doSubmit('01')">提交</el-button>
          <el-button v-if="form.bisZhsqZt === '80'" type="info" @click="zhHistoryQuery()">查看意见</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column align="center" prop="bisZhsqZt" label="申请状态" width="130">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.bisZhsqZt === '05'" effect="plain" type="">
              {{ dict.label.zhzt[scope.row.bisZhsqZt] }}
            </el-tag>
            <el-tag v-else-if="scope.row.bisZhsqZt === '00'" effect="plain" type="warning">
              {{ dict.label.zhzt[scope.row.bisZhsqZt] }}
            </el-tag>
            <el-tag v-else effect="plain" type="danger">
              {{ dict.label.zhzt[scope.row.bisZhsqZt] }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="lrsj" label="申请时间" width="150" />
        <el-table-column align="center" prop="bisZhsqYbkh" label="医保卡号" width="90" />
        <el-table-column align="center" prop="bisZhsqSnryXm" label="姓名" />
        <el-table-column align="center" prop="bisZhsqSnryXb" label="性别" />
        <el-table-column align="center" prop="bisZhsqSnrySfz" label="身份证" width="150" />
        <el-table-column align="center" prop="bisZhsqCblx" label="参保类型" width="70" />
        <el-table-column align="center" prop="bisZhsqNl" label="年龄" />
        <el-table-column prop="bisZhsqDykkrq" label="待遇开始日期" width="100" />
        <el-table-column prop="bisZhsqDyjsrq" label="待遇结束日期" width="100" />
        <el-table-column align="center" prop="bisZhsqSndj" label="失能等级" width="90" />
        <el-table-column align="center" prop="bisZhsqHldzSsqxName" label="居住所在区县" width="130" />
        <el-table-column align="center" prop="bisZhsqAdl" label="ADL评分" />
        <el-table-column align="center" prop="bisZhsqLxdh" label="联系电话" width="100" />
        <el-table-column align="center" prop="bisZhsqJhrxm" label="监护人姓名" />
        <el-table-column align="center" prop="bisZhsqJhrdh" label="监护人电话" width="130" />
        <el-table-column align="center" prop="bisZhsqGxName" label="关系" width="70" />
        <el-table-column align="center" prop="bisZhsqSnryYbssqxName" label="医保所属区县" width="130" />
        <el-table-column v-if="checkPer(['admin','zhsq:edit'])" fixed="right" label="操作" width="290px" align="center">
          <template slot-scope="scope">
            <el-button
              :loading="crud.status.cu === 2"
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="crud.toEdit(scope.row)"
            >
              修改
            </el-button>
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-delete"
              hidden
              @click.native.prevent="doOpenCancel(scope.row)"
            >
              作废
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
      <!--Drawer 抽屉，隐藏失能人员列表-->
      <el-drawer
        title="患者信息"
        :visible.sync="snryDrawer"
        direction="rtl"
        size="60%"
      >

        <div v-if="true" style="margin-left: 20px;">
          <!-- 搜索 -->
          <el-radio-group v-model="radio4" size="mini" class="filter-item">
            <el-radio-button label="ReadCardBas" name="医保卡">医保卡</el-radio-button>
            <el-radio-button label="ReadSFZ" name="身份证">身份证</el-radio-button>
          </el-radio-group>
          <!--          <el-button class="filter-item" size="mini" type="primary" icon="el-icon-bank-card" v-loading.fullscreen.lock="fullscreenLoading" @click="read">读 卡</el-button>-->
        </div>
        <div style="margin-left: 20px;">
          <!-- 搜索 -->
          <el-input v-model="ybrySfzh" clearable size="small" placeholder="输入身份证号" disabled style="width: 200px;" class="filter-item" @keyup.enter.native="ybryQuery" />
          <el-button v-loading.fullscreen.lock="fullscreenLoading" class="filter-item" size="mini" type="success" icon="el-icon-search" :loading="snryDataloading" @click="read">读卡搜索</el-button>
          <el-button v-if="false" class="filter-item" size="mini" type="success" icon="el-icon-search" :loading="snryDataloading" @click="ybryQuery">搜索</el-button>
        </div>
        <el-table ref="table" v-loading="snryDataloading" :data="snryData">
          <el-table-column type="index" :index="indexMethod" label="序号" align="center" />
          <el-table-column prop="aac003" label="姓名" align="center" />88
          <el-table-column prop="xb" label="性别" align="center" />
          <el-table-column prop="aab034Name" label="参保统筹区" align="center" />
          <el-table-column prop="aac001" label="个人编码" align="center" width="100px" />
          <el-table-column prop="aac002" label="身份证" align="center" width="150px" />
          <el-table-column prop="cardno" label="医保卡号" align="center" width="100px" />
          <el-table-column prop="aac008" label="参保类型" align="center" width="100px" />
          <el-table-column prop="aac031" label="参保状态" align="center" width="100px" />
          <el-table-column prop="akc021" label="人员类型" align="center" width="100px" />
          <el-table-column prop="begnDate" label="封锁起始日期" align="center" width="100px" />
          <el-table-column prop="endDate" label="封锁截止日期" align="center" width="100px" />
          <el-table-column prop="pausTypeName" label="封锁类别" align="center" width="100px" />
          <el-table-column prop="chgReaDscr" label="封锁原因" align="center" width="100px" />
          <el-table-column
            fixed="right"
            label="操作"
            width="120"
          >
            <template slot-scope="scope">
              <el-button
                type="text"
                size="small"
                @click.native.prevent="selectRow(scope.$index, snryData)"
              >
                确定
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-drawer>
      <!--Drawer 抽屉，隐藏ADL量表列表-->
      <el-drawer
        title="ADL量表"
        :visible.sync="adlDrawer"
        :before-close="handleClose"
        direction="rtl"
        size="40%"
      >
        <div v-for="(adlXmItem, adlXmIndex) in adlData" :key="adlXmIndex" style="margin-left: 20px;">
          <div style="margin-bottom: 5px;">{{ (adlXmIndex+1) + "、" + adlXmItem.adlXmName }}</div>
          <div>
            <el-radio-group v-model="adlXmItem.adlXmGroup">
              <div v-for="(adlXmxxItem, adlXmxxIndex) in adlXmItem.adlXmList" :key="adlXmxxIndex" style="margin-left: 10px; margin-bottom: 5px;">
                <el-radio :label="adlXmxxItem.adlXmxxId">{{ adlXmxxItem.adlXmxxName }}({{ adlXmxxItem.adlXmxxFs }}分)</el-radio>
              </div>
            </el-radio-group>
          </div>
        </div>
        <div style="margin-bottom: 20px; margin-top: 10px; margin-left: 58%;">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="success" @click="adlSubmit">确 认</el-button>
        </div>
      </el-drawer>
      <el-dialog :visible.sync="dialogYjFormVisible" width="720px">
        <el-table ref="yjtable" v-loading="zhHistoryDataloading" :data="zhHistoryData">
          <el-table-column type="index" :index="indexMethod" label="序号" align="center" />
          <el-table-column prop="lrsj" label="操作时间" align="center" />
          <el-table-column prop="lrrxm" label="操作人" align="center" />
          <el-table-column prop="type" label="操作类型" align="center">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.type === '02'" effect="plain" type="success">
                评估
              </el-tag>
              <el-tag v-else-if="scope.row.type === '04'" effect="plain" type="primary">
                复核
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="result" label="操作结果" align="center" />
          <el-table-column prop="bz" label="意见" align="center" width="200px" />
        </el-table>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogYjFormVisible = false">关 闭</el-button>
        </div>
      </el-dialog>
      <el-dialog title="原因" :visible.sync="dialogCancleFormVisible" width="500px">
        <el-form>
          <el-form-item label="作废原因">
            <el-input v-model="cancleCause" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button :loading="cancleStaus === 2" @click="dialogCancleFormVisible = false">取 消</el-button>
          <el-button :loading="cancleStaus === 2" type="primary" @click="cancle()">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog title="申请调整待遇开始日期" :visible.sync="dialogChangeTimeFormVisible" width="500px">
        <el-form ref="form" :inline="true" :model="form" label-width="90px">
          <el-form-item label="姓名" prop="dialogChangeTimeXm">
            <el-input v-model="dialogChangeTimeXm" type="text" style="width: 290px;" disabled />
          </el-form-item>
          <el-form-item label="身份证" prop="dialogChangeTimeSfz">
            <el-input v-model="dialogChangeTimeSfz" type="text" style="width: 290px;" disabled />
          </el-form-item>
          <el-form-item label="日期" prop="bisZhsqRq">
            <el-date-picker v-model="bisZhsqRq" type="date" value-format="yyyy-MM-dd" format="yyyy-MM-dd" placeholder="调整的日期" style="width: 290px;" />
          </el-form-item>
          <el-form-item label="原因" prop="bisZhsqYy">
            <el-input v-model="bisZhsqYy" :rows="3" type="textarea" style="width: 290px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button :loading="timeStaus === 2" @click="dialogChangeTimeFormVisible = false">取 消</el-button>
          <el-button :loading="timeStaus === 2" type="primary" @click="changeTime()">确 定</el-button>
        </div>
      </el-dialog>
      <image-viewer
        v-if="showImgViewer"
        :url-list="imgPreviewUrl"
        :on-close="() => {showImgViewer = false}"
        :z-index="3000"
      />
    </div>
  </div>
</template>

<script>
import crudZhsq from '@/api/business/zhsq'
import crudFile from '@/api/tools/localStorage'
import crudZhsqTzdyrq from '@/api/business/zhsqTzdyrq'
import { mapGetters } from 'vuex'
import { getToken } from '@/utils/auth'
import { getYbry } from '@/api/business/ybry'
import { getAdlXmxx } from '@/api/business/adlXmxx'
import { queryThisHljg } from '@/api/business/hljg'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import moment from 'moment'
import ImageViewer from 'element-ui/packages/image/src/image-viewer'
import axios from 'axios'

const defaultForm = { bisZhsqId: null, bisZhsqHljgId: null, bisZhsqSnryId: null, bisZhsqSnryXm: null, bisZhsqSnryXb: null, bisZhsqSnrySfz: null, bisZhsqDykkrq: null, bisZhsqYbkh: null, bisZhsqCbzt: null, bisZhsqDyjsrq: null, bisZhsqXsdyq: null, bisZhsqAdl: null, bisZhsqZt: null, bisZhsqSnryYbssqx: null, ywlx: null, lrr: null, lrrxm: null, lrbm: null, lrbmmc: null, lrsj: null, gxr: null, gxrxm: null, gxbm: null, gxbmmc: null, gxsj: null, bz: null, bisZhsqAdlPc: null, bisZhsqSndj: null, bisZhsqRybh: null, bisZhsqNl: null, bisZhsqLxdh: null, bisZhsqHldzSsqx: null, bisZhsqHldzXxdz: null, bisZhsqHldz: null, bisZhsqJhrxm: null, bisZhsqJhrdh: null, bisZhsqGx: null, bisZhsqSqyy: null, bisZhsqGrbh: null, adlZhsqs: [], bisZhsqCblx: null, bisZhsqSqlb: null, bisZhsqTjsj: null }
export default {
  name: 'Zhsq',
  components: { pagination, crudOperation, rrOperation, ImageViewer },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['xb', 'yjsgx', 'ccs', 'zhzt', 'ccstcqh', 'sqlb'],
  cruds() {
    return CRUD({ title: '照护申请', url: 'api/zhsq', idField: 'bisZhsqId', sort: 'bisZhsqId,desc', crudMethod: { ...crudZhsq }})
  },
  data() {
    return {
      dialogYjFormVisible: false,
      dialogCancleFormVisible: false,
      dialogCancleZhid: '',
      dialogChangeTimeFormVisible: false,
      dialogChangeTimeZhid: '',
      dialogChangeTimeXm: '',
      dialogChangeTimeSfz: '',
      dialogChangeTimeTcq: '',
      bisZhsqRq: '',
      bisZhsqYy: '',
      snryDrawer: false,
      ybrySfzh: '',
      adlDrawer: false,
      /* ALD选题按钮是否可用 */
      adlIsDisabled: false,
      snryData: [],
      zhHistoryData: [],
      adlData: [],
      headers: { 'Authorization': getToken() },
      /* 上传附件时，附件类别（病历） */
      fjlb_bl: { 'fjlb': 'BL' },
      /* 上传附件时，附件类别（社会保障卡） */
      fjlb_shbzk: { 'fjlb': 'SHBZK' },
      /* 上传附件时，附件类别（身份证） */
      fjlb_sfz: { 'fjlb': 'SFZ' },
      /* 上传附件时，附件类别（ADL量表） */
      fjlb_adl: { 'fjlb': 'orgAdlLiveVideo' },
      /* 默认加载上传的文件列表 */
      file_list_bl: [],
      file_list_shbzk: [],
      file_list_sfz: [],
      file_list_adl: [],
      districts: [],
      fileIds: '',
      fileVideoIds: '',
      fileAllIds: '',
      showImgViewer: false,
      imgPreviewUrl: [], // 当前要放大的图片存放位置
      sbIsExist: true,
      pgIsExist: true,
      sstcq: '',
      snryDataloading: false,
      zhHistoryDataloading: false,
      fullscreenLoading: false,
      radio4: 'ReadCardBas',
      percent: 0,
      total: 0,
      isSuccess: false,
      fileUploading: false,
      cancleCause: '',
      cancleStaus: 1,
      timeStaus: 1,
      cblxTypeOptions: [
        { key: '城乡居民', display_name: '城乡居民' },
        { key: '城镇职工', display_name: '城镇职工' }
      ],
      sndjTypeOptions: [
        { key: '中度失能', display_name: '中度失能' },
        { key: '重度失能', display_name: '重度失能' },
        { key: '85周岁以上', display_name: '85周岁以上' },
        { key: '90周岁以上', display_name: '90周岁以上' }
      ],
      permission: {
        add: ['admin', 'zhsq:add'],
        edit: ['admin', 'zhsq:edit'],
        del: ['admin', 'zhsq:del']
      },
      rules: {
        bisZhsqSnryXm: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        bisZhsqSnryXb: [
          { required: true, message: '性别不能为空', trigger: 'blur' }
        ],
        bisZhsqSnrySfz: [
          { required: true, message: '身份证不能为空', trigger: 'blur' }
        ],
        bisZhsqHldz: [
          { required: true, message: '地址不能为空', trigger: 'blur' }
        ],
        bisZhsqJhrxm: [
          { required: true, message: '监护人姓名不能为空', trigger: 'blur' }
        ],
        bisZhsqJhrdh: [
          { required: true, message: '监护人电话不能为空', trigger: 'blur' }
        ],
        bisZhsqGx: [
          { required: true, message: '与失能人员关系不能为空', trigger: 'blur' }
        ],
        bisZhsqSqyy: [
          { required: true, message: '申请原因不能为空', trigger: 'blur' }
        ],
        bisZhsqSqlb: [
          { required: true, message: '申请类别不能为空', trigger: 'blur' }
        ],
        bisZhsqAdl: [
          { required: true, message: '选择ADL量表', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    ...mapGetters([
      'baseApi',
      'fileUploadApi',
      'minioUploadImageApi',
      'minioMpUploadImageApi',
      'formatVideo',
      'minioUploadVideoApi',
      'minioMpUploadVideoApi',
      'imagesUploadApi',
      'user'
    ])
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    /**
     * 点击新建/编辑之前
     * @param crud
     * @param form
     * @returns {boolean}
     */
    [CRUD.HOOK.beforeToCU]() {
      this.queryThisHljg()
      this.queryAllQyJd()
      return true
    },
    /**
     * 点击新建之前
     * @param crud
     * @param form
     * @returns {boolean}
     */
    [CRUD.HOOK.beforeToAdd]() {
      this.adlIsDisabled = false
      this.file_list_bl = []
      this.file_list_shbzk = []
      this.file_list_sfz = []
      this.file_list_adl = []
      this.fileAllIds = ''
      this.fileIds = ''
      this.fileVideoIds = ''
      return true
    },
    /**
     * 点击修改之前
     * @param crud
     * @param form
     * @returns {boolean}
     */
    [CRUD.HOOK.beforeToEdit](crud, form) {
      console.log(form)
      this.file_list_bl = []
      this.file_list_shbzk = []
      this.file_list_sfz = []
      this.file_list_adl = []
      this.fileAllIds = ''
      this.fileIds = ''
      this.fileVideoIds = ''
      // 清空附件列表
      var bisZhsqZt = form.bisZhsqZt
      var bisZhsqSnryXm = form.bisZhsqSnryXm
      if (bisZhsqZt === '00' || bisZhsqZt === '80') {
        this.adlIsDisabled = false
        this.getFiles()
        return true
      } else if (bisZhsqZt === '-5' || bisZhsqZt === '-4') {
        this.$notify({
          title: bisZhsqSnryXm + '的照护申请被驳回，重新申请',
          type: 'warning',
          duration: 2500
        })
        return false
      } else {
        this.$notify({
          title: bisZhsqSnryXm + '的照护申请已提交，无法修改',
          type: 'warning',
          duration: 2500
        })
        return false
      }
    },
    /**
     * 点击删除之前校验
     * @param crud
     * @param form
     * @returns {boolean}
     */
    [CRUD.HOOK.beforeDelete](crud, form) {
      var bisZhsqZt = form.bisZhsqZt
      var bisZhsqSnryXm = form.bisZhsqSnryXm
      if (bisZhsqZt === '00') {
        return true
      } else {
        this.$notify({
          title: bisZhsqSnryXm + '的照护申请已提交，无法删除',
          type: 'warning',
          duration: 2500
        })
        return false
      }
    },
    /**
     * 序号
     * @param index
     * @returns {*}
     */
    indexMethod(index) {
      return index + 1
    },
    /**
     * 弹出申请修改时间页面
     * @param zt
     */
    doOpenChangeTime(row) {
      if (row.bisZhsqTjsjFlag === '1') {
        this.$notify({
          title: '已经调整过申请日期，不允许多次申请',
          type: 'warning',
          duration: 2500
        })
        return
      }
      console.log(row)
      this.dialogChangeTimeZhid = row.bisZhsqId
      this.dialogChangeTimeXm = row.bisZhsqSnryXm
      this.dialogChangeTimeSfz = row.bisZhsqSnrySfz
      this.dialogChangeTimeTcq = row.bisZhsqSnryYbssqx
      this.dialogChangeTimeFormVisible = true
    },
    /**
     * 申请修改时间
     * @param index
     * @param rows
     */
    changeTime() {
      if (this.bisZhsqRq === '') {
        this.$notify({
          title: '请填写调整日期',
          type: 'warning',
          duration: 2500
        })
        return
      }
      if (this.bisZhsqYy === '') {
        this.$notify({
          title: '请填写调整原因',
          type: 'warning',
          duration: 2500
        })
        return
      }
      this.$confirm(`你确定将待遇开始日期调整到${this.bisZhsqRq}吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.timeStaus = 2
        const data = {
          bisZhsqId: this.dialogChangeTimeZhid,
          bisZhsqXm: this.dialogChangeTimeXm,
          bisZhsqSfz: this.dialogChangeTimeSfz,
          bisZhsqYbssqx: this.dialogChangeTimeTcq,
          bisZhsqRq: this.bisZhsqRq,
          bisZhsqYy: this.bisZhsqYy
        }
        crudZhsqTzdyrq.add(data)
          .then(res => {
            this.$notify({
              title: '操作成功',
              type: 'success',
              duration: 2500
            })
            this.dialogChangeTimeFormVisible = false
            this.timeStaus = 1
            this.crud.toQuery()
          })
          .catch(err => {
            this.dialogChangeTimeFormVisible = false
            this.timeStaus = 1
            console.log(err)
          })
      })
    },
    /**
     * 弹出退回页面
     * @param zt
     */
    doOpenCancel(row) {
      this.dialogCancleZhid = row.bisZhsqId
      this.dialogCancleFormVisible = true
    },
    /**
     * 作废
     * @param index
     * @param rows
     */
    cancle() {
      if (this.cancleCause === '') {
        this.$notify({
          title: '请填写作废原因',
          type: 'warning',
          duration: 2500
        })
        return
      }
      this.$confirm('你确定作废此照护申请吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.cancleStaus = 2
        const data = { zhid: this.dialogCancleZhid, cause: this.cancleCause }
        crudZhsq.cancelZhsq(data)
          .then(res => {
            this.$notify({
              title: '操作成功',
              type: 'success',
              duration: 2500
            })
            this.dialogCancleFormVisible = false
            this.cancleStaus = 1
            this.crud.toQuery()
          })
          .catch(err => {
            this.dialogCancleFormVisible = false
            this.cancleStaus = 1
            console.log(err)
          })
      })
    },
    /**
     * 确认选择的失能人员
     * @param index
     * @param rows
     */
    selectRow(index, rows) {
      const snry = rows[index]
      /*
      if (this.user.username === '1875' ||
        this.user.username === '1945' ||
        this.user.username === '1ZC11' ||
        this.user.username === '1Y64' ||
        this.user.username === '1Z95') {
        // 鑫夕阳、广禾、汇德、悦和、明珠
        if (!(snry.aab034Code === this.sstcq || snry.aab034Code === '220101')) {
          this.$message({
            showClose: true,
            message: '此人医保所属统筹区为【' + snry.aab034Name + '】，本院为【' + this.dict.label.ccstcqh[this.sstcq] + '】，不符合申请条件',
            type: 'warning'
          })
          return
        }
      } else {
        if (snry.aab034Code !== this.sstcq) {
          this.$message({
            showClose: true,
            message: '此人医保所属统筹区为【' + snry.aab034Name + '】，本院为【' + this.dict.label.ccstcqh[this.sstcq] + '】，不符合申请条件',
            type: 'warning'
          })
          return
        }
      }
      */
      // 申请时允许：1、本县机构申请市级参保人员；2、本县机构申请本县参保人员；3、市级机构申请外县参保人员；4、市级机构申请市级参保人员
      // 外县机构申请非本县参保人员不可以
      if (snry.aab034Code === this.sstcq) {
        console.log('人员参保区和机构统筹区一致')
      } else {
        console.log('人员参保区和机构统筹区不一致')
        console.log('人员:', snry.aab034Code)
        console.log('机构:', this.sstcq)
        if (this.sstcq === '220101') {
          console.log('入住本市机构')
        } else {
          if (snry.aab034Code === '220101' && this.sstcq !== '220101') {
            console.log('市本级入住外县机构')
          } else {
            // 双阳夕阳红、双阳心乐、德惠福利院
            this.$message({
              showClose: true,
              message: '此人医保所属统筹区为【' + snry.aab034Name + '】，本院为【' + this.dict.label.ccstcqh[this.sstcq] + '】，不符合申请条件',
              type: 'warning'
            })
            return
          }
        }
      }

      // 校验参保状态
      if (snry.aac031 === '停保') {
        this.$message({
          showClose: true,
          message: '此人【已停保】，无法申请照护待遇',
          type: 'warning'
        })
        return
      }
      // 校验是否缴费
      if (snry.clctClag === '') {
        this.$message({
          showClose: true,
          message: '此人【未缴费】，无法申请照护待遇',
          type: 'warning'
        })
        return
      }
      // 校验人员类型
      if (snry.akc021 === '离休或一级保健对象') {
        this.$message({
          showClose: true,
          message: '人员类型为【离休或一级保健对象】，无法申请照护待遇',
          type: 'warning'
        })
        return
      }
      // 校验是否住院
      // 校验是否正在享受待遇
      if (snry.akb021 !== '') {
        this.$message({
          showClose: true,
          message: '此人正在【' + snry.akb021 + '】享受照护待遇，无法申请',
          type: 'warning'
        })
        return
      }
      if (snry.pausType === '2' || snry.pausType === '3') {
        this.$message({
          showClose: true,
          message: '此人【' + snry.chgReaDscr + '】，无法申请',
          type: 'warning'
        })
        return
      }
      this.snryDrawer = false

      // const csrq = snry.aac002.substring(6, 13)
      const csnd = snry.aac002.substring(6, 10)
      const csrq = snry.aac002.substring(10, 14)
      // const csnd = 1937
      // const csrq = 1208
      const currentNd = moment(new Date()).format('YYYY')
      const currentRq = moment(new Date()).format('MMDD')
      // 当前日期 >= 出生日期的，年龄+1
      const nl = currentRq >= csrq ? currentNd - csnd : currentNd - csnd - 1

      this.form.bisZhsqGrbh = snry.aac001
      this.form.bisZhsqSnryXm = snry.aac003
      this.form.bisZhsqSnryXb = snry.xb
      this.form.bisZhsqSnrySfz = snry.aac002
      this.form.bisZhsqYbkh = snry.cardno
      this.form.bisZhsqCbzt = snry.aac031
      this.form.bisZhsqCblx = snry.aac008
      this.form.bisZhsqSnryYbssqx = snry.aab034Code
      this.form.bisZhsqNl = nl
      // this.form.bisZhsqNl = 85
    },
    /**
     * 打开失能人员时，实时查询
     */
    getSnry() {
      this.snryDrawer = true
      this.ybrySfzh = ''
      this.snryData = []
    },
    /**
     * 查询医保人员
     */
    ybryQuery() {
      if (this.ybrySfzh === '') {
        this.$message({
          showClose: true,
          message: '请输入查询条件',
          type: 'warning'
        })
        return
      }

      this.snryDataloading = true
      getYbry({ sfzh: this.ybrySfzh }).then(res => {
        this.snryData = res.content
        this.snryDataloading = false
      }).catch(err => {
        this.snryDataloading = false
        console.log(err.data.message)
      })
    },
    /**
     * 查询医保人员
     */
    zhHistoryQuery() {
      this.dialogYjFormVisible = true
      console.log(this.zhHistoryData.length === 0)
      if (this.zhHistoryData.length === 0) {
        this.zhHistoryDataloading = true
        crudZhsq.getZhHistory({ zhsqId: this.form.bisZhsqId, sort: 'lrsj,desc' }).then(res => {
          console.log(res)
          this.zhHistoryData = res.content
          this.zhHistoryDataloading = false
        }).catch(err => {
          this.zhHistoryDataloading = false
          console.log(err.data.message)
        })
      }
    },
    /**
     * 打开ADL量表时，实时查询
     */
    getAdl() {
      if (this.adlIsDisabled) {
        this.$message({
          dangerouslyUseHTMLString: true,
          showClose: true,
          message: 'ADL量表已完成，修改时无法操作',
          type: 'warning'
        })
      } else {
        this.adlDrawer = true
        if (this.crud.status.add === 1 && this.crud.status.edit === 0) { // 点击新增按钮，提交的时候只是新增
          getAdlXmxx().then(res => {
            console.log(res)
            this.adlData = res.adlData
            this.form.bisZhsqAdlPc = res.adlPcId
          })
        } else if (this.crud.status.add === 0 && this.crud.status.edit === 1) { // 修改照护申请时，不允许修改ADL量表
          getAdlXmxx().then(res => {
            console.log(res)
            this.adlData = res.adlData
            this.form.bisZhsqAdlPc = res.adlPcId
          })
        }
      }
    },
    /**
     * 修改操作时，需要加载附件信息
     */
    getFiles() {
      crudFile.queryFileByFjlb2(this.form.bisZhsqId).then(res => {
        for (let i = 0; i < res.length; i++) {
          const file = res[i]
          if (file.fjlb === 'orgAdlLiveVideo') {
            const obj = { 'id': file.id, 'name': file.name, 'url': file.path2 }
            this.file_list_adl.push(obj)
            this.fileVideoIds += file.id + ','
          }
        }
      })
    },
    /**
     * 记录ADL量表，并计算ADL量表总分数
     */
    adlSubmit() {
      // 是否被选中
      let selected = false
      // 未被选中的项目
      let allUnSelectedName = ''
      // ADL量表总分数
      let adlfx = 0
      // 清空选中的adl量表内容
      this.form.adlZhsqs = []
      this.adlData.map((item, index) => {
        // 项目ID
        const adlXmId = item.adlXmId
        // 项目分组
        const adlXmGroup = item.adlXmGroup
        // 项目名称
        const adlXmName = item.adlXmName
        // 项目名称
        const adlXmPx = item.adlXmPx
        // 项目选项列表
        const adlXmList = item.adlXmList

        if (adlXmId === adlXmGroup) {
          selected = selected || true
          allUnSelectedName += adlXmPx + '、' + adlXmName + '<br>'
        } else {
          for (const adlxmxx of adlXmList) {
            // 项目选项ID
            const adlXmxxId = adlxmxx.adlXmxxId
            // 项目选项分数
            const adlXmxxFs = parseInt(adlxmxx.adlXmxxFs)
            if (adlXmGroup === adlXmxxId) {
              this.form.adlZhsqs.push(adlxmxx)
              adlfx += adlXmxxFs
            }
          }
        }
        // eslint-disable-next-line no-empty
      })
      console.log('总分：' + JSON.stringify(this.form))
      if (selected) {
        this.$message({
          dangerouslyUseHTMLString: true,
          showClose: true,
          message: allUnSelectedName + '<br>没有被选中',
          type: 'warning'
        })
      } else {
        console.log('年龄：' + this.form.bisZhsqNl)
        if (this.form.bisZhsqNl >= 85 && this.form.bisZhsqNl < 90) {
          console.log('分数：' + this.form.bisZhsqAdl)
          if (adlfx !== 100) {
            this.adlDrawer = false
            this.form.bisZhsqAdl = adlfx
          } else {
            this.$message({
              dangerouslyUseHTMLString: true,
              showClose: true,
              message: '大于85周岁小于90周岁的老人，ADL量表结果禁止评100分',
              type: 'warning'
            })
          }
        } else {
          this.adlDrawer = false
          this.form.bisZhsqAdl = adlfx
        }
      }
    },
    /**
     * 自定义保存
     * @param zt
     */
    doSave(zt) {
      this.fileAllIds = this.fileVideoIds
      this.form.bisZhsqZt = zt
      const titleMsg = '保存成功'
      this.crud.findVM('form').$refs['form'].validate(valid => {
        if (!valid) {
          return
        }

        if (this.crud.status.add === 1 && this.crud.status.edit === 0) { // 点击新增按钮，提交的时候只是新增
          this.crud.status.add = CRUD.STATUS.PROCESSING
          crudZhsq.add(this.form, this.fileAllIds)
            .then(res => {
              this.crud.status.add = CRUD.STATUS.NORMAL
              this.$notify({
                title: titleMsg,
                type: 'success',
                duration: 2500
              })
              this.crud.toQuery()
            })
            .catch(err => {
              this.crud.status.add = CRUD.STATUS.PREPARED
              console.log(err)
            })
        } else if (this.crud.status.add === 0 && this.crud.status.edit === 1) { // 点击修改按钮，提交的时候只是修改
          this.crud.status.edit = CRUD.STATUS.PROCESSING
          crudZhsq.edit(this.form, this.fileAllIds)
            .then(res => {
              this.crud.status.edit = CRUD.STATUS.NORMAL
              this.$notify({
                title: titleMsg,
                type: 'success',
                duration: 2500
              })
              this.crud.toQuery()
            })
            .catch(err => {
              this.crud.status.edit = CRUD.STATUS.PREPARED
              console.log(err)
            })
        }
      })
    },
    /**
     * 自定义保存
     * @param zt
     */
    doSubmit(zt) {
      if (!this.sbIsExist) {
        if (this.form.bisZhsqNl < 85) {
          if (this.fileVideoIds === '') {
            this.$notify({
              title: '提交时，需要上传视频',
              type: 'error',
              duration: 2500
            })
            return
          }
        }
      }
      this.fileAllIds = this.fileVideoIds
      this.form.bisZhsqZt = zt
      const titleMsg = '提交成功'
      this.crud.findVM('form').$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        if (this.crud.status.add === 1 && this.crud.status.edit === 0) { // 点击新增按钮，提交的时候只是新增
          this.crud.status.add = CRUD.STATUS.PROCESSING
          crudZhsq.submitZhsq(this.form, this.fileAllIds)
            .then(res => {
              this.crud.status.add = CRUD.STATUS.NORMAL
              this.$notify({
                title: titleMsg,
                type: 'success',
                duration: 2500
              })
              this.crud.toQuery()
            })
            .catch(err => {
              this.crud.status.add = CRUD.STATUS.PREPARED
              console.log(err)
            })
        } else if (this.crud.status.add === 0 && this.crud.status.edit === 1) { // 点击修改按钮，提交的时候只是修改
          this.crud.status.edit = CRUD.STATUS.PROCESSING
          crudZhsq.submitZhsq(this.form, this.fileAllIds)
            .then(res => {
              this.crud.status.edit = CRUD.STATUS.NORMAL
              this.$notify({
                title: titleMsg,
                type: 'success',
                duration: 2500
              })
              this.crud.toQuery()
            })
            .catch(err => {
              this.crud.status.edit = CRUD.STATUS.PREPARED
              console.log(err)
            })
        }
      })
    },
    /**
     * ADL量表关闭
     */
    handleClose() {
      this.$confirm('关闭以后，选择的内容将会消失，确认关闭？')
        .then(_ => {
          this.adlDrawer = false
        })
        .catch(_ => {})
    },
    /**
     * 上传前校验
     * @param file
     * @returns {boolean}
     */
    beforeUpload(file) {
      let isLt2M = true
      isLt2M = file.size / 1024 / 1024 < 10
      if (!isLt2M) {
        this.loading = false
        this.$message.error('上传文件大小不能超过 10MB!' + (file.size / 1024 / 1024))
      }
      return isLt2M
    },
    /**
     * 视频上传前校验
     * @param file
     * @returns {boolean}
     */
    beforeVideoUpload(file) {
      let isLt2M = true
      isLt2M = file.size / 1024 / 1024 < 150
      if (!isLt2M) {
        this.loading = false
        // this.$message.error('上传文件大小不能超过 200MB!' + (file.size / 1024 / 1024))
        this.$notify({
          title: '上传文件大小不能超过 150MB!',
          type: 'error',
          duration: 5000
        })
      }
      return isLt2M
    },
    /**
     * 删除前确认提示
     * @param file
     * @returns {Promise<MessageBoxData>}
     */
    beforeRemove(file) {
      console.log('删除前确认提示 :{}', file)
      return this.$confirm(`删除操作会直接删除此图片，确定删除 ${file.name}？`)
    },
    /**
     * 图片预览
     * @param file
     */
    handlePreview(file) {
      console.log('图片预览 :{}', file)
      if (file.response) {
        this.imgPreviewUrl[0] = file.response.data.url2
        window.open(file.response.data.url2)
      } else {
        this.imgPreviewUrl[0] = file.url
        window.open(file.url)
      }
    },
    /**
     * 文件上传成功时的钩子
     * @param response
     * @param file
     * @param fileList
     */
    handleSuccess(response, file, fileList) {
      console.log('文件上传成功时的钩子response :{}, file{}', response, file)
      this.fileIds += response.data.id + ','
      this.crud.notify('上传成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
    },
    /**
     * 视频上传成功时的钩子
     * @param response
     * @param file
     * @param fileList
     */
    handleVideoSuccess(response, file, fileList) {
      console.log('文件上传成功时的钩子response :{}, file{}', response, file)
      this.fileVideoIds += response.data.id + ','

      // crudFile.updateYwid2ById(response.data.adlXmGroup, file.data.id).then(res => {})
      this.crud.notify('上传成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
      this.isSuccess = true
      this.fileUploading = false
    },
    handleProgress(event) {
      console.log(event)
      this.fileUploading = true
    },
    /**
     * 移除文件
     * @param file
     * @param fileList
     */
    handleRemove(file, fileList) {
      console.log('移除文件 :{}', file, fileList)
      crudFile.del([file.id]).then(res => {})
    },
    /**
     * 监听上传失败
     * @param e
     * @param file
     * @param fileList
     */
    handleError(e, file, fileList) {
      const msg = JSON.parse(e.message)
      this.$notify({
        title: msg.message,
        type: 'error',
        duration: 2500
      })
      this.loading = false
    },
    /**
     * 查询本机构，是否绑定对应的商保/评估公司
     * false：未绑定；true：绑定
     */
    queryThisHljg() {
      queryThisHljg().then(res => {
        this.sbIsExist = res.sbIsExist
        this.pgIsExist = res.pgIsExist
        this.sstcq = res.sstcq
      })
    },
    queryAllQyJd() {
      crudZhsq.queryAllQyJd().then(res => {
        console.log('res: {} ', res)
        var a = []
        for (const item of res) {
          item.label = item.bisQyName
          item.value = item.bisQyRowId
          for (const child of item.children) {
            child.label = child.bisQyName
            child.value = child.bisQyRowId
          }
          a.push(item)
        }
        this.districts = a
      })
    },
    onchange(e) {
      console.log('选择的区/县街道:{}', e)
      this.form.bisZhsqHldzSsqx = e[0]
    },
    // 获取弹窗内评估公司数据
    read() {
      this.fullscreenLoading = true
      axios.get('http://127.0.0.1:19995?MSG=' + this.radio4).then(res => {
        console.log('res:', res)
        this.fullscreenLoading = false
        const DllReturn = res.data.DllReturn
        if (this.radio4 === 'ReadCardBas') {
          const shbzkContent = res.data.pCardInfo
          console.log('ReadCardBas:', shbzkContent)
          if (DllReturn === '0') {
            const contentList = shbzkContent.split('|')
            this.ybrySfzh = contentList[1]
          } else {
            this.$notify({
              title: shbzkContent + '。请重新读卡',
              type: 'warning',
              duration: 2500
            })
            return
          }
        } else {
          const pOutBuff = res.data.pOutBuff
          console.log('else:', pOutBuff)
          if (DllReturn === '0') {
            this.ybrySfzh = pOutBuff.split('|')[0]
            if (this.ybrySfzh.length !== 18) {
              this.ybrySfzh = pOutBuff.split('|')[5]
            }
          } else {
            this.$notify({
              title: pOutBuff + '。请将身份证放入正确位置',
              type: 'warning',
              duration: 2500
            })
            return
          }
        }
        this.ybryQuery()
      }).catch(err => {
        this.fullscreenLoading = false
        console.log('err: {} ', err)
      })
    }
  }
}
</script>

<style scoped>
.progress{
  width: 100%;
  margin-left: 10px;
}
.total{
  padding-left: 20px;
  font-size:13px;
}
</style>
